package com.juyu.miliao.scheduler.dao.mysql;

import com.juyu.miliao.common.dataSource.tool.distributeOperate.DistributeOperate;
import com.juyu.miliao.common.dataSource.tool.operate.Operate;
import com.juyu.miliao.scheduler.domin.UserCount;
import org.apache.ibatis.session.SqlSession;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Repository
public class UserCountDao {
	@Resource
	private SqlSession sqlSession;

	@Operate("strategy('byUserId', #userId)")
    public int reduceMGradeSum(long userId, double mGradeSum) {
        Map<String, Object> params = new HashMap<>(4);
		params.put("userId", userId);
		params.put("mGradeSum", mGradeSum);
		return sqlSession.update("reduceMGradeSum", params);
	}

	@DistributeOperate(ds = "miliao-user")
	public List<UserCount> findUserCountMVGradeSum(int startNum, int pageSize){
		Map<String, Object> params = new HashMap<>();
		params.put("startNum", startNum);
		params.put("pageSize", pageSize);
		return sqlSession.selectList("findUserCountMVGradeSum", params);
	}

	@DistributeOperate(ds = "miliao-user")
	public int countUserCountNum(){
		return sqlSession.selectOne("countUserCountNum");
	}

	
	@Operate("strategy('byUserId', #userId)")
	public int reduceVGradeSum(long userId, int vGradeSum){
		Map<String, Object> params = new HashMap<>();
		params.put("userId", userId);
		params.put("vGradeSum", vGradeSum);
		return sqlSession.update("reduceVGradeSum", params);
	}
	@Operate("strategy('byUserId', #userId)")
    public int plusUserCountEnergy(long userId, int energySum) {
		Map<String, Object> params = new HashMap<>();
		params.put("userId", userId);
		params.put("energySum", energySum);
		return sqlSession.update("plusUserCountEnergy",params);
    }

	@Operate("strategy('byUserId', #userId)")
	public int updateIntegralSum(long userId, int integralValue) {
		Map<String, Object> params = new HashMap<>(4);
		params.put("userId", userId);
		params.put("integralValue", integralValue);
		return sqlSession.update("updateIntegralSum",params);
	}
}
